package com.chezai.client.server.util;


import com.chezai.client.server.NettyChannel;

import io.netty.channel.Channel;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;

/**
 * 通道帮助类
 * 
 * @author shenliuyang
 *
 *         2016年8月12日下午2:58:47
 */
public class ChannelUtil {

    /**
     * 获取通道
     * 
     * @param c
     * @return
     */
    public static com.jx.driving.protocol.terminal.channel.Channel getChannel(Channel c) {
	AttributeKey<com.jx.driving.protocol.terminal.channel.Channel> key = AttributeKey.valueOf("CHANNEL_WRAP");
	Attribute<com.jx.driving.protocol.terminal.channel.Channel> attr = c.attr(key);
	com.jx.driving.protocol.terminal.channel.Channel channel = attr.get();
	if (channel != null) {
	    return channel;
	}
	channel = new NettyChannel(c);
	attr.set(channel);
	return channel;
    }
}
